/**
 * filename:myjs.js
 * @author liudm 
 */

//仪表盘相关函数
function updategauge1(gauge1,val)
{
	gauge1.value=val;
	RGraph.Effects.Gauge.Grow(gauge1);
}
//原水电导率
function drawgauge1_ys_ddl(ctrl)
{
	var gauge = new RGraph.Gauge(ctrl, 0, 2000, 890);
	gauge.Set('chart.scale.decimals', 0);
	gauge.Set('chart.tickmarks.small', 50);
	gauge.Set('chart.tickmarks.big',5);
	gauge.Set('chart.title.top', '');
	gauge.Set('chart.title.top.size', 24);
	gauge.Set('chart.title.bottom', '原水电导率');
	gauge.Set('chart.colors.ranges', [[1200, 1600, 'yellow'],[1600, 2000, 'red']]);
	gauge.Set('chart.adjustable', true);
	gauge.Draw(); 
    return gauge;
}
//原水瞬时流量
function drawgauge1_ys_ssll(ctrl)
{
	var gauge = new RGraph.Gauge(ctrl, 0.0, 100, 65);
	gauge.Set('chart.scale.decimals', 0);
	gauge.Set('chart.tickmarks.small', 50);
	gauge.Set('chart.tickmarks.big',5);
	gauge.Set('chart.title.top', '');
	gauge.Set('chart.title.top.size', 24);
	gauge.Set('chart.title.bottom', '原水瞬时流量');
	gauge.Set('chart.colors.ranges', [[90, 95, 'yellow'],[95, 100, 'red']]);
	gauge.Set('chart.adjustable', true);
	gauge.Draw();
    return gauge;
}

//原水总流量
function drawgauge1_ys_zll(ctrl)
{
	var gauge = new RGraph.Gauge(ctrl, 0.0, 10000, 4500);
	gauge.Set('chart.scale.decimals', 0);
	gauge.Set('chart.tickmarks.small', 50);
	gauge.Set('chart.tickmarks.big',5);
	gauge.Set('chart.title.top', '');
	gauge.Set('chart.title.top.size', 24);
	gauge.Set('chart.title.bottom', '原水总流量');
	gauge.Set('chart.colors.ranges', [[8000, 9000, 'yellow'],[9000, 10000, 'red']]);
	gauge.Set('chart.adjustable', true);
	gauge.Draw();
    return gauge;
}


//原水压力
function drawgauge1_ys_yl(ctrl)
{
	var gauge = new RGraph.Gauge(ctrl, 0.0, 10, 8.5);
    gauge.Set('chart.scale.decimals', 0);
    gauge.Set('chart.tickmarks.small', 50);
    gauge.Set('chart.tickmarks.big',5);
    gauge.Set('chart.title.top', '');
    gauge.Set('chart.title.top.size', 24);
    gauge.Set('chart.title.bottom', '原水压力');
	gauge.Set('chart.colors.ranges', [[8, 9, 'yellow'],[9, 10, 'red']]);
    gauge.Set('chart.adjustable', true);
    gauge.Draw(); 
    return gauge;
}

//直饮水电导率
function drawgauge1_zys_ddl(ctrl)
{
	var gauge = new RGraph.Gauge(ctrl, 0, 300, 75);
	gauge.Set('chart.scale.decimals', 0);
	gauge.Set('chart.tickmarks.small', 50);
	gauge.Set('chart.tickmarks.big',5);
	gauge.Set('chart.title.top', '');
	gauge.Set('chart.title.top.size', 24);
	gauge.Set('chart.title.bottom', '直饮水电导率');
	gauge.Set('chart.colors.ranges', [[200, 250, 'yellow'],[250, 300, 'red']]);
	gauge.Set('chart.adjustable', true);
	gauge.Draw();  
	return gauge;
}
//直饮水瞬时流量
function drawgauge1_zys_ssll(ctrl)
{
	var gauge6 = new RGraph.Gauge(ctrl, 0.0, 100, 55);
    gauge6.Set('chart.scale.decimals', 0);
    gauge6.Set('chart.tickmarks.small', 50);
    gauge6.Set('chart.tickmarks.big',5);
    gauge6.Set('chart.title.top', '');
    gauge6.Set('chart.title.top.size', 24);
    gauge6.Set('chart.title.bottom', '直饮水瞬时流量');
	gauge6.Set('chart.colors.ranges', [[90, 95, 'yellow'],[95, 100, 'red']]);
    gauge6.Set('chart.adjustable', true);
    gauge6.Draw();
    return gauge6;
}

//直饮水总流量
function drawgauge1_zys_zll(ctrl)
{
	var gauge7 = new RGraph.Gauge(ctrl, 0.0, 10000, 4500);
    gauge7.Set('chart.scale.decimals', 0);
    gauge7.Set('chart.tickmarks.small', 50);
    gauge7.Set('chart.tickmarks.big',5);
    gauge7.Set('chart.title.top', '');
    gauge7.Set('chart.title.top.size', 24);
    gauge7.Set('chart.title.bottom', '直饮水总流量');
	gauge7.Set('chart.colors.ranges', [[8000, 9000, 'yellow'],[9000, 10000, 'red']]);
    gauge7.Set('chart.adjustable', true);
    gauge7.Draw();  
    return gauge7;
}
//供水压力
function drawgauge1_zys_yl(ctrl)
{
	var gauge8 = new RGraph.Gauge(ctrl, 0.0, 10, 8.5);
    gauge8.Set('chart.scale.decimals', 0);
    gauge8.Set('chart.tickmarks.small', 50);
    gauge8.Set('chart.tickmarks.big',5);
    gauge8.Set('chart.title.top', '');
    gauge8.Set('chart.title.top.size', 24);
    gauge8.Set('chart.title.bottom', '供水压力');
	gauge8.Set('chart.colors.ranges', [[8, 9, 'yellow'],[9, 10, 'red']]);
    gauge8.Set('chart.adjustable', true);
    gauge8.Draw();   
    return gauge8;
}
function initAllGauge(width)
{
	var gauge1 = drawgauge1_ys_ddl('cvs1');
    var gauge2 = drawgauge1_ys_ssll('cvs2'); 
    var gauge3 = drawgauge1_ys_zll('cvs3');
    var gauge4 = drawgauge1_ys_yl('cvs4');
    var gauge5 = drawgauge1_zys_ddl('cvs5');
    var gauge6 = drawgauge1_zys_ssll('cvs6');
    var gauge7 = drawgauge1_zys_zll('cvs7');
    var gauge8 = drawgauge1_zys_yl('cvs8');
    $("#cvs1").width(width);
    $("#cvs1").height(width);
    $("#cvs2").width(width);
    $("#cvs2").height(width);    
    $("#cvs3").width(width);
    $("#cvs3").height(width);    
    $("#cvs4").width(width);
    $("#cvs4").height(width);
    $("#cvs5").width(width);
    $("#cvs5").height(width);
    $("#cvs6").width(width);
    $("#cvs6").height(width);
    $("#cvs7").width(width);
    $("#cvs7").height(width);
    $("#cvs8").width(width);
    $("#cvs8").height(width);
    
    var gaugelist = [gauge1,gauge2,gauge3,gauge4,gauge5,gauge6,gauge7,gauge8];
    return gaugelist;
}
function UpdateAllGauge1 (gauges,vals) {
	for(var i in gauges)
	{	
		var val = 0;
		if(vals.length>i)
			val = vals[i];
		updategauge1(gauges[i],val);
	}
}
function refreshGauge(devsn,gauges) 
{
	console.log("call into refreshGauge  ");
	var surl = "getNewOneDevStatus?devsn="+devsn+"&structid=0"
	var vals = new Array(10);
	for(var i in vals)
		vals[i] = 0;
    $.ajax({
        type: "post",
        global:false,
        //async:false, 
        contentType: "application/json",
        dataType: "json",
        timeout: 1500, //超时时间设置，单位毫秒
        url: surl,
        data: {},
        success: function(data) {
            if (data.success) 
            {
            	vals[0] = data.devOneDevStatus.tdsinflow;
            	vals[1] = data.devOneDevStatus.waterflow;
            	vals[2] = data.devOneDevStatus.quantityinflow;
            	vals[3] = data.devOneDevStatus.presureinflow; 
            	vals[4] = data.devOneDevStatus.tdsoutflow;
            	vals[5] = data.devOneDevStatus.phoutflow;
            	vals[6] = data.devOneDevStatus.quantityoutflow;
            	vals[7] = data.devOneDevStatus.wateroutflow;
            	vals[8] = data.devOneDevStatus.presureoutflow;
            	vals[9] = data.devOneDevStatus.phinflow;
            	UpdateAllGauge1(gauges,vals);
            }
        },
        complete: function(XMLHttpRequest, status) { //请求完成后最终执行参数
            if (status == 'timeout') { //超时,status还有success,error等值的情况
                　　　　　
                //ajaxTimeoutTest.abort();　　　　　
                //alert("超时");　　　　
            }　　
        },
        error: function(textStatus, errorThrown) {
            //alert(XMLHttpRequest.status + "<br>" + XMLHttpRequest.readyState + "<br>" + "<br>" + textStatus);
        	//ajaxTimeoutTest.abort();
        	//alert(XMLHttpRequest.status);
        }
    });
}
function parseUrl(url){
	  var result = [];
	  var query = url.split("?")[1];
	  var queryArr = query.split("&");
	  queryArr.forEach(function(item){
	    var obj = {};
	    var value = item.split("=")[0];
	    var key = item.split("=")[1];
	    obj[key] = value;
	    result.push(obj);
	  });
	  return result;
}
function parseUrlParam(url,param){
	  var query = url.split("?")[1];
	  var queryArr = query.split("&");
	  queryArr.forEach(function(item){
	    var obj = {};
	    var value = item.split("=")[0];
	    var key = item.split("=")[1];
	    obj[key] = value;
	    if(param==key)
	    	return value;
	  });
	  return "";
}
function getUrlParam(name) {
	 var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
	 alert(window.location);
	 var r = window.location.search.substr(1).match(reg); //匹配目标参数
	 if (r != null) return unescape(r[2]); return null; //返回参数值
}
(function ($) {
	  $.getUrlParam = function (name) {
	   var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
	   var r = window.location.search.substr(1).match(reg);
	   if (r != null) return unescape(r[2]); return null;
	  }
})(jQuery);

function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "/";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    
    var weekdaynumber=date.getDay();//获取存储当前日期
    var weekday=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
    var sweekday = weekday[weekdaynumber];
    var sHour = date.getHours();
    if (sHour >= 0 && sHour <= 9) {
    	sHour = "0" + sHour;
    }
    var sMinute = date.getMinutes();
    if (sMinute >= 0 && sMinute <= 9) {
    	sMinute = "0" + sMinute;
    }    
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
            + " " + sweekday +" " + sHour + seperator2 + sMinute;//+ seperator2 +date.getSeconds();
            //+ seperator2 + date.getSeconds();
    return currentdate;
}

